<html>
<head><meta charset="utf-8"><title>error: higher-ranked subtype error · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/error.3A.20higher-ranked.20subtype.20error.html">error: higher-ranked subtype error</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="206212972"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/error%3A%20higher-ranked%20subtype%20error/near/206212972" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/error.3A.20higher-ranked.20subtype.20error.html#206212972">(Aug 07 2020 at 00:23)</a>:</h4>
<p>Oh dear, I just got this not-very-helpful error message: "error: higher-ranked subtype error"</p>



<a name="206213026"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/error%3A%20higher-ranked%20subtype%20error/near/206213026" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/error.3A.20higher-ranked.20subtype.20error.html#206213026">(Aug 07 2020 at 00:24)</a>:</h4>
<p>I have this function:</p>
<div class="codehilite"><pre><span></span><code>pub fn link_name&lt;F&gt;(check_name: F, attrs: &amp;[ast::Attribute]) -&gt; Option&lt;Symbol&gt;
where
    F: Fn(&amp;ast::Attribute, Symbol) -&gt; bool
</code></pre></div>



<a name="206213056"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/error%3A%20higher-ranked%20subtype%20error/near/206213056" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/error.3A.20higher-ranked.20subtype.20error.html#206213056">(Aug 07 2020 at 00:25)</a>:</h4>
<p>And I have this error:</p>
<div class="codehilite"><pre><span></span><code>error: higher-ranked subtype error
    --&gt; src/librustc_typeck/collect.rs:2618:25
     |
2618 |     if let Some(name) = weak_lang_items::link_name(check_name, &amp;attrs) {
     |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
</code></pre></div>



<a name="206213078"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/error%3A%20higher-ranked%20subtype%20error/near/206213078" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/error.3A.20higher-ranked.20subtype.20error.html#206213078">(Aug 07 2020 at 00:25)</a>:</h4>
<p>It's not a very helpful error message :(</p>



<a name="206213177"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/error%3A%20higher-ranked%20subtype%20error/near/206213177" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/error.3A.20higher-ranked.20subtype.20error.html#206213177">(Aug 07 2020 at 00:27)</a>:</h4>
<p><code>check_name</code> is a closure, and I guess it doesn't match <code>Fn(&amp;ast::Attribute, Symbol) -&gt; bool</code> somehow</p>



<a name="206213247"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/error%3A%20higher-ranked%20subtype%20error/near/206213247" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/error.3A.20higher-ranked.20subtype.20error.html#206213247">(Aug 07 2020 at 00:28)</a>:</h4>
<p>The closure is this: <code>let check_name = |attr, sym| { tcx.sess.check_name(attr, sym) };</code></p>



<a name="206213415"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/error%3A%20higher-ranked%20subtype%20error/near/206213415" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/error.3A.20higher-ranked.20subtype.20error.html#206213415">(Aug 07 2020 at 00:32)</a>:</h4>
<p>Is that with <code>#![feature(nll)]</code>?</p>



<a name="206213424"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/error%3A%20higher-ranked%20subtype%20error/near/206213424" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/error.3A.20higher-ranked.20subtype.20error.html#206213424">(Aug 07 2020 at 00:32)</a>:</h4>
<p>IIRC, the error is somewhat better without it</p>



<a name="206213564"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/error%3A%20higher-ranked%20subtype%20error/near/206213564" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/error.3A.20higher-ranked.20subtype.20error.html#206213564">(Aug 07 2020 at 00:36)</a>:</h4>
<p>This is in rustc itself, so I assume it's using NLL</p>



<a name="206213609"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/error%3A%20higher-ranked%20subtype%20error/near/206213609" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/error.3A.20higher-ranked.20subtype.20error.html#206213609">(Aug 07 2020 at 00:36)</a>:</h4>
<p>I did find <a href="https://github.com/rust-lang/rust/issues/57374">https://github.com/rust-lang/rust/issues/57374</a>, but couldn't extract anything useful from it</p>



<a name="206213654"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/error%3A%20higher-ranked%20subtype%20error/near/206213654" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/error.3A.20higher-ranked.20subtype.20error.html#206213654">(Aug 07 2020 at 00:37)</a>:</h4>
<p>That issue suggests that lifetimes might somehow be a problem?</p>



<a name="206213996"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/error%3A%20higher-ranked%20subtype%20error/near/206213996" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yuki Okushi <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/error.3A.20higher-ranked.20subtype.20error.html#206213996">(Aug 07 2020 at 00:44)</a>:</h4>
<p>yeah, I recently encountered this unhelpful diagnostics in <a href="https://github.com/rust-lang/rust/issues/74889">#74889</a> :(</p>



<a name="206214132"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/error%3A%20higher-ranked%20subtype%20error/near/206214132" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/error.3A.20higher-ranked.20subtype.20error.html#206214132">(Aug 07 2020 at 00:47)</a>:</h4>
<p>I think I might need a <code>for&lt;'a&gt;</code> ?</p>



<a name="206215125"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/error%3A%20higher-ranked%20subtype%20error/near/206215125" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/error.3A.20higher-ranked.20subtype.20error.html#206215125">(Aug 07 2020 at 01:07)</a>:</h4>
<p>A few explicit lifetimes ended up fixing it:</p>
<div class="codehilite"><pre><span></span><code>pub fn link_name&lt;&#39;a, F&gt;(check_name: F, attrs: &amp;&#39;a [ast::Attribute]) -&gt; Option&lt;Symbol&gt;
where
    F: Fn(&amp;&#39;a ast::Attribute, Symbol) -&gt; bool
</code></pre></div>



<a name="206215585"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/error%3A%20higher-ranked%20subtype%20error/near/206215585" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/error.3A.20higher-ranked.20subtype.20error.html#206215585">(Aug 07 2020 at 01:16)</a>:</h4>
<p><span class="user-mention" data-user-id="120989">@njn</span> what's the signature of <code>sess.check_name</code>?</p>



<a name="206215606"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/error%3A%20higher-ranked%20subtype%20error/near/206215606" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/error.3A.20higher-ranked.20subtype.20error.html#206215606">(Aug 07 2020 at 01:17)</a>:</h4>
<p><code>pub fn check_name(&amp;self, attr: &amp;Attribute, name: Symbol) -&gt; bool</code></p>



<a name="207507274"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/error%3A%20higher-ranked%20subtype%20error/near/207507274" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/error.3A.20higher-ranked.20subtype.20error.html#207507274">(Aug 20 2020 at 10:12)</a>:</h4>
<p><span class="user-mention" data-user-id="120989">@njn</span> <span class="user-mention" data-user-id="217081">@Yuki Okushi</span>  I should ask in the issue but have we been able to create a standalone test case that reproducces the problem?</p>



<a name="207507303"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/error%3A%20higher-ranked%20subtype%20error/near/207507303" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/error.3A.20higher-ranked.20subtype.20error.html#207507303">(Aug 20 2020 at 10:13)</a>:</h4>
<p>well I guess <a href="https://github.com/rust-lang/rust/pull/74889/">https://github.com/rust-lang/rust/pull/74889/</a> might be one</p>



<a name="207507310"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/error%3A%20higher-ranked%20subtype%20error/near/207507310" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/error.3A.20higher-ranked.20subtype.20error.html#207507310">(Aug 20 2020 at 10:13)</a>:</h4>
<p>ok</p>



<a name="207507315"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/error%3A%20higher-ranked%20subtype%20error/near/207507315" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/error.3A.20higher-ranked.20subtype.20error.html#207507315">(Aug 20 2020 at 10:13)</a>:</h4>
<p>that helps</p>



<a name="207507323"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/error%3A%20higher-ranked%20subtype%20error/near/207507323" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/error.3A.20higher-ranked.20subtype.20error.html#207507323">(Aug 20 2020 at 10:13)</a>:</h4>
<p>/me considers some coding therapy...</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>